package org.voidness.squaretilesframework.sprites;

import java.awt.Dimension;

import org.voidness.oje2d.GLImage;

/** Represents one frame for a sprite animation */
public class GLHotSpotFrame {
    /** The associated image */
    private GLImage image = null;

    /** The hotspot value for the frame */
    private Dimension hotspot = null;

    /**
     * Default constructor
     * 
     * @param mImage The image to set
     * @param mHotspot The hotspot for the frame
     */
    public GLHotSpotFrame(GLImage mImage, Dimension mHotspot) {
        image = mImage;
        hotspot = mHotspot;
    }

    /**
     * Another constructor. This time with the hotspot split in two
     * 
     * @param mImage The image to set
     * @param mHotX The hotspot's X coordinate
     * @param mHotY The hotspot's Y coordinate
     */
    public GLHotSpotFrame(GLImage mImage, int mHotX, int mHotY) {
        image = mImage;
        hotspot = new Dimension(mHotX, mHotY);
    }

    /**
     * Get the hotspot position
     * 
     * @return The hotspot dimension
     */
    public Dimension getHotSpot() {
        return hotspot;
    }

    /**
     * Returns the hotspot's location
     * 
     * @return The X component of the location
     */
    public int getHotSpotX() {
        return hotspot.width;
    }

    /**
     * Returns the hotspot's location
     * 
     * @return The Y component of the location
     */
    public int getHotSpotY() {
        return hotspot.height;
    }

    /**
     * Reloads this frame
     */
    public void reload() {
        image.reload();
    }

    /**
     * Returns the image's path
     * 
     * @return A string holding the relative path to the image
     */
    public String getImagePath() {
        return image.getFilename();
    }

    /**
     * Draws this frame with the hotspot at mX,mY
     * 
     * @param mX The target tile's center X coordinate
     * @param mY The target tile's center Y coordinate
     * @param mAlpha The alpha to use when drawing
     */
    public void draw(int mX, int mY, float mAlpha) {
        // Do the calculations based on the hotspot to
        // draw the image in the right position
        image.draw(mX - hotspot.width, mY - hotspot.height, mAlpha);

        // Draw hotspot
        // Engine.drawDot(mX, mY, 5, GLColor.RED);
    }

    /**
     * Clones this frame
     * 
     * @return A new instance of the frame
     */
    public Object clone() {
        return new GLHotSpotFrame((GLImage) image.clone(), (Dimension) hotspot
                .clone());
    }
}